﻿<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp "&#x00A0;">
]>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  xmlns:umbraco.library="urn:umbraco.library"
  xmlns:uQR="urn:uQR"
  exclude-result-prefixes="msxml umbraco.library uQR ">

  <xsl:output method="xml" omit-xml-declaration="yes"/>

  <xsl:param name="currentPage"/>

  <xsl:variable name="data">
    <xsl:choose>
      <xsl:when test="string-length(/macro/qrCodeData) &gt; 0">
        <xsl:value-of select="/macro/qrCodeData"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="concat('http://', umbraco.library:RequestServerVariables('HTTP_HOST'), umbraco.library:RequestServerVariables('URL'))"/>
        <xsl:if test="string-length(umbraco.library:RequestServerVariables('QUERY_STRING')) &gt; 0">
          <xsl:value-of select="concat('?', umbraco.library:RequestServerVariables('QUERY_STRING'))"/>
        </xsl:if>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="width">
    <xsl:choose>
      <xsl:when test="string-length(/macro/qrCodeWidth) &gt; 0">
        <xsl:value-of select="/macro/qrCodeWidth"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="200"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="height">
    <xsl:choose>
      <xsl:when test="string-length(/macro/qrCodeHeight) &gt; 0">
        <xsl:value-of select="/macro/qrCodeHeight"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$width"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="correction">
    <xsl:choose>
      <xsl:when test="string-length(/macro/qrCodeCorrection) &gt; 0">
        <xsl:value-of select="/macro/qrCodeCorrection"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="'M'"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:template match="/">
    <img src="{uQR:GetQRCodeUrl($data, $width, $height, $correction)}" alt="QR Code for '{$data}'" width="{$width}" height="{$height}" />
  </xsl:template>

</xsl:stylesheet>